package com.springboot.config;

import com.springboot.servlet.Filter_;
import com.springboot.servlet.Listener_;
import com.springboot.servlet.Servlet_;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.sql.Array;
import java.util.Arrays;

/**
 * 1.RegisterCon_ 是一个配置类
 * 2.proxyBeanMethods = true ：默认是单例
 * 通过 RegistrationBean 方式注入servlet
 */
@Configuration(proxyBeanMethods = true)
public class RegisterCon_ {
    @Bean
    public ServletRegistrationBean servlet_() {
        //创建原生的servlet对象
        Servlet_ servlet_ = new Servlet_();
        //Servlet_对象关联到ServletRegistrationBean对象
        // "/servlet01", "/servlet02" 表示注入servlet的url-pattern
        return new ServletRegistrationBean(servlet_, "/servlet01", "/servlet02");
    }

    @Bean
    public FilterRegistrationBean filter_() {
        Filter_ filter_ = new Filter_();//创建原生的Filter
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(filter_);
        //设置过滤器的url-pattern属性
        filterRegistrationBean.setUrlPatterns(Arrays.asList("/manger.html"));
        return filterRegistrationBean;
    }
    public ServletListenerRegistrationBean listener_(){
        //创建原生的listener_
        Listener_ listener_ = new Listener_();
        return new ServletListenerRegistrationBean<>(listener_);
    }
}
